import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const AuditList= []
const count = 100

for (let i = 0; i < count; i++) {
  AuditList.push(Mock.mock({
    id:'@increment(1, 100)',
    account: '@first',
    time:  +Mock.Random.date('T'),
    applyTime:  +Mock.Random.date('T'),
    auditFirTime:  +Mock.Random.date('T'),
    auditSecTime:  +Mock.Random.date('T'),
    registerIp:Mock.Random.ip(),
    name: '@first',
    auditFirManager: '@first',
    auditSecManager: '@first',
    reason: Mock.Random.ctitle(20),
    auditFirComment: Mock.Random.ctitle(0,20),
    auditSecComment: Mock.Random.ctitle(0,20),
    whoApply: '@first',
    proxy: '@float(0, 100, 2, 2)',
    level: '@integer(1, 3)',
    balance: '@float(60, 100, 1)',
    editContent:'@float(60, 100, 1)',
    'accountType|1': ['CN', 'US', 'JP', 'EU'],
    'editType|1': ['CN', 'US', 'JP', 'EU'],
    'auditFirStatus|1': [0,1,2],
    'auditSecStatus|1': [0,1,2],
  }))
}

export default {
  [api.AUDIT_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = AuditList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.AUDIT_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    console.log('id',id)

    _.map(AuditList,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
  [api.AUDIT_UPDATE]: config => {
    const { id,step,comment,status } = param2Obj(config.body)
    _.map(AuditList,item=>{
      if(item.id == id){
        if(step==1){
          item.auditFirComment = comment
          item.auditFirStatus = status
        }else{
          item.auditSecComment = comment
          item.auditSecStatus = status
        }
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        msg: '修改成功'
      },
      code: 1,
    };
  },
  [api.AUDIT_APPLIER_LIST]: config =>{
    return {
      data: {
        list:  AuditList.splice(0,5),
      },
      code: 1,
    };
  },
  [api.AUDIT_MAN_LIST]: config =>{
    const {step} = param2Obj(config.body)
    let _list = []
    if(step== 1){
      _list =  AuditList.splice(0,5)
    }else{
      _list =  AuditList.splice(5,5)
    }
    return {
      data: {
        list: _list
      },
      code: 1,
    };
  },
  [api.AUDIT_OPERATOR]: config =>{
    let _list =  AuditList.splice(5,10)
    return {
      data: {
        list: _list
      },
      code: 1,
    };
  },
}
